<?php

namespace App\Kit;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class Token
{
    private static $key = "hll-secret";
    private static $alg = "HS256";
    private static $keyId = "hll";

    public static function createToken($data, $id, $iss,  $expire = 7200){
        $payload = [
            'iss' => $iss,
            'sub' => $id,
            'iat' => time(),
            'exp' => time() + $expire,
            'data' => $data
        ];
        return JWT::encode($payload, self::$key, self::$alg, self::$keyId);
    }

    public static function decodeToken($token){
        try {
            $payload = JWT::decode($token, new Key(self::$key, self::$alg));
        } catch(\Exception $e) {
            return false;
        }

        return $payload;
    }

}
